package com.android.juvid.testnet;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.support.v7.app.ActionBar.LayoutParams;
import android.graphics.Color;
public class AddViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_add_view );
        final LayoutInflater inflater = LayoutInflater.from(this);

//        RelativeLayout layout = (RelativeLayout) inflater.inflate(
//                R.layout.activity_main, null).findViewById(
//                R.id.relativeLayout);

        RelativeLayout layout = (RelativeLayout) findViewById(
                R.id.relativeLayout);

//        final RelativeLayout lin = (RelativeLayout) findViewById(R.id.relativeLayout);
//        // 获取需要添加的布局
//        RelativeLayout layout =new  RelativeLayout(this);
//        lin.addView(layout);


        layout.setBackgroundColor(0xff00ffff);
        RelativeLayout.LayoutParams LP_MM = new RelativeLayout.LayoutParams( ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
        layout.setLayoutParams(LP_MM);
//        this.addContentView(  );
        ImageView imageView= new ImageView(this);
        imageView.setBackgroundResource(R.mipmap.ic_launcher);
        RelativeLayout.LayoutParams PARA = new RelativeLayout.LayoutParams(80,80);
//        PARA.x=12;
        imageView.setLayoutParams(PARA);
        layout.addView(imageView);

        TextView tv = new TextView(this); // 普通聊天对话
        tv.setText("我和猫猫是新添加的");
        tv.setBackgroundColor(Color.GRAY);
        RelativeLayout.LayoutParams LP_WW = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        tv.setLayoutParams(LP_WW);
        layout.addView(tv);
//        TextView juTextV=(TextView)findViewById( R.id.juTextView );
//        layout.removeView(juTextV);

        setContentView(layout);

    }
}
